package com.han.yrpc.core;

import com.han.yrpc.core.runtime.YrpcServer;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class CustomApplicationContext extends AnnotationConfigApplicationContext {

    public CustomApplicationContext(Class<?> componentClasses) {
        super(componentClasses);
    }

    @Override
    public void register(Class<?>... componentClasses) {
        super.register(componentClasses);

        for (Class<?> componentClass : componentClasses) {
            YrpcScan yrpcScan = componentClass.getAnnotation(YrpcScan.class);
            if (yrpcScan != null) {
                scan(yrpcScan.basePackage());
            }
        }
    }

    @Override
    public void onRefresh() {
        YrpcServer server = getBean(YrpcServer.class);
        new Thread(server::start).start();
    }

}
